﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Test.Entities
{
	public abstract class Account : ChildIdentifiableEntity, IAccount
	{
		#region Fields

		private DateTime _dateCreated;
		private DateTime _dateUpdated;

		#endregion

		#region Constructors

		protected Account()
		{
			Owner = new Lazy<User>();
			Parent = new Lazy<IAccount>();
		}

		#endregion

		#region Properties

		[Required]
		public string Name { get; set; }
		
		[Required]
		public AccountStatus Status { get; set; }
		
		public IList<Address> Addresses { get; set; }
		
		public DateTime DateCreated
		{
			get
			{
				if (_dateCreated == DateTime.MinValue)
				{
					_dateCreated = DateTime.Now;
				}

				return _dateCreated;
			}
			set
			{
				_dateCreated = value;
			}
		}
		
		public DateTime DateUpdated
		{
			get
			{
				if (_dateUpdated == DateTime.MinValue)
				{
					_dateUpdated = DateTime.Now;
				}

				return _dateUpdated;
			}
			set
			{
				_dateUpdated = value;
			}
		}

		public Guid OwnerId { get; set; }

		public Lazy<User> Owner { get; set; }

		public Lazy<IAccount> Parent { get; set; }

		#endregion
	}
}